//
//  GSDKUserForgotPasswordView.m
//  GameSDK
//
//  Created by Johnny on 2017/8/6.
//  Copyright © 2017年 Johnny. All rights reserved.
//

#import "GSDKUserForgotPasswordView.h"
#import "GSDKCommonMethod.h"
#import "YYKit.h"
@interface GSDKUserForgotPasswordView()
@property (nonatomic, retain) UIImageView * logoImageView;
@property (nonatomic, retain) UIView * contentView;
@property (nonatomic, retain) UILabel * connectLabel;
@property (nonatomic, retain) UIButton * backButton;
@property (nonatomic, retain) UIButton * cancelButton;
@property (nonatomic, retain) NSDictionary * titleLabelDic;

@end

@implementation GSDKUserForgotPasswordView
- (void)dealloc {
    DEBUGMSG(@"GSDKUserForgotPasswordView dealloc");
}
- (id)init {
    self = [super init];
    if (self != nil) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    self.layer.cornerRadius = 4;
    
    _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_backButton setTitle:[NSString stringWithFormat:@" %@", [NSString localizedStringForKey:@"GSDK_back_text" value:@"返回"]] forState:UIControlStateNormal];
    [_backButton setTitleColor:[UIColor colorWithHexString:@"#b9b9b9"] forState:UIControlStateNormal];
    _backButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [_backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [_backButton setImage:[UIImage imageNamed:@"ZYSDK_Resourcres.bundle/pic/left"] forState:UIControlStateNormal];
    _backButton.frame = CGRectMake(10, 8, 50, 30);
    [self addSubview:_backButton];
    
    _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
    [_cancelButton setImage:[UIImage imageNamed:@"ZYSDK_Resourcres.bundle/pic/close"] forState:UIControlStateNormal];
    _cancelButton.frame = CGRectMake(UserViewWidth - 40, 10, 30, 30);
    [self addSubview:_cancelButton];
    
    _logoImageView = [[UIImageView alloc] init];
    _logoImageView.image = [UIImage imageNamed:@"ZYSDK_Resourcres.bundle/pic/newLogo"];
    _logoImageView.frame = CGRectMake(UserViewWidth/2 - 119.7/2, 15, 119.7, 35);
    [self addSubview:_logoImageView];
    
    _connectLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 55, UserViewWidth-30*2, 40)];
    if (UserViewWidth < 320) {
        _connectLabel.numberOfLines = 2;
    }
    _connectLabel.text = [NSString localizedStringForKey:@"GSDK_fotgotpd_notice" value:@"您可以通过以下方式找回密码:"];
    _connectLabel.textColor = [UIColor colorWithHexString:@"#777777"];
    _connectLabel.font = [UIFont systemFontOfSize:13.5];
    [self addSubview:_connectLabel];
    
    NSArray * titleLabelArray = @[[NSString localizedStringForKey:@"GSDK_email_text" value:@"邮箱"]];
    
    NSArray * titleImageArray = @[@"ZYSDK_Resourcres.bundle/pic/home"];
    for (int i = 0 ; i< titleLabelArray.count ; i ++) {
        UIButton * connectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        connectButton.tag = i;
        connectButton.backgroundColor = [UIColor colorWithHexString:@"#0197d2"];
        connectButton.frame =CGRectMake(30, 105 + i * (40+10), UserViewWidth-30*2, 40);
        connectButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [connectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        connectButton.titleLabel.font = [UIFont systemFontOfSize:UserViewWidth <= 315 ? 13 : 14];
        NSString * labelStr = [NSString stringWithFormat:@"%@",titleLabelArray[i]];
        [connectButton setTitle:labelStr forState:0];
        UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",titleImageArray[i]]];
        [connectButton setImage:image forState:0];
        [connectButton addTarget:self action:@selector(forgotAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:connectButton];
        connectButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        connectButton.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
        connectButton.layer.cornerRadius = 2;
        connectButton.layer.masksToBounds = YES;
    }
}

#pragma mark --- Action
- (void)backAction {
    if (_backBlock) {
        _backBlock();
    }
}

- (void)forgotAction:(UIButton*)button {
    ForgotPasswordType type = (ForgotPasswordType)button.tag;
    if (_forgotPasswordBlock) {
        _forgotPasswordBlock(type);
    }
}

- (void)cancelAction {
    [[NSNotificationCenter defaultCenter] postNotificationName:GSDKUserCancelNoticationName object:nil];
}

@end
